﻿using Abp;
using Abp.Json;
using Abp.Web.Models;

namespace NetCore.ServiceGroup
{
    public static class AjaxResponseExtensions
    {
        /// <summary>
        /// 验证并返回结果
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="ajaxResponse"></param>
        /// <returns></returns>
        public static TResult ToResult<TResult>(this AjaxResponse<TResult> ajaxResponse)
        {
            if (!ajaxResponse.Success)
            {
                throw new AbpException(ajaxResponse.Error.ToJsonString());
            }
            return ajaxResponse.Result;
        }
    }
}
